package com.jdwx.opengl.kotlin

open class Rectangle2 {
    open fun draw() {
        println("Rectangle2")
        /* …… */ }
}

interface Polygon {
    fun draw() {
        println("Polygon")
        /* …… */
    } // 接口成员默认就是“open”的
}
interface Text{
    fun test(){
        println("test")
    }
}

class Square() : Rectangle2(), Polygon,Text {
    // 编译器要求覆盖 draw()：
    override fun draw() {
        super<Rectangle2>.draw() // 调用 Rectangle.draw()
        super<Polygon>.draw() // 调用 Polygon.draw()
    }
    override fun test(){

    }

}
open class Polygon1 {
    open fun draw() {}
}

open abstract class Rectangle1 : Polygon1() {
    override abstract fun draw()
}

class Rectangle3: Rectangle1() {
    override fun draw() {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }


}
interface MyInterface {
    fun bar()
    fun foo() {
        // 可选的方法体
    }
}

fun main(){

    var square = Square();
    square.draw()

    class Address {
        var name: String = "Holmes, Sherlock"
        var street: String = "Baker"
        var city: String = "London"
        var state: String? = null
        var zip: String = "123456"
        var allByDefault: Int?  = null// 错误：需要显式初始化器，隐含默认 getter 和 setter
        var initialized = 1 // 类型 Int、默认 getter 和 setter
        val simple: Int? // 类型 Int、默认 getter、必须在构造函数中初始化
        val inferredType = 1 // 类型 Int 、默认 getter
        constructor( simple: Int ){
            this.simple =  simple
        }

        var stringRepresentation: String
            get() = this.toString()
            set(value) {
                this.city = value
            }
        var size = 0
        val isEmpty get() = this.size == 0  // 具有类型 Boolean

        var setterVisibility: String = "abc"
             set( name ){
             } // 此 setter 是私有的并且有默认实现

        var setterWithAnnotation: Any? = null

        var counter = 0 // 注意：这个初始器直接为幕后字段赋值
            set(value) {
                if (value >= 0) field = value
            }

    }

    println( Address(10).city )


    println( Address(10).stringRepresentation )

    var add = Address(10)
    add.stringRepresentation = "重庆"

    println( add.city )
    println( add.isEmpty )
    println( add.setterVisibility )
    add.setterVisibility = "1000"
    println( add.setterVisibility )


    class Child : MyInterface {
        override fun bar() {
            // 方法体
            println( "bar" )
        }
    }

    var child = Child()

    child.bar()




    class Child2 : MyInterface2 {
        override val prop: Int = 29
    }

    var child2 = Child2()
    child2.foo()
    println( child2.propertyWithImplementation )

}
interface MyInterface2 {
    val prop: Int // 抽象的

    val propertyWithImplementation: String
        get() = "foo"

    fun foo() {
        println(prop)
    }


}